package sort;

/**
 * @author:李雄
 * @ClassName:DubbleSort
 * @Description:冒泡排序
 * @createTime:2022-11-13 20:58
 */
public class BubbleSort {

    public static void main(String[] args) {
        int arr[] = new int[]{13, 30, 54, 26, 15};
        myBubbleSort(arr);
        for (int i = 0; i < arr.length; i++) {
            System.out.println(arr[i]);
        }
    }

    public static void myBubbleSort(int arr[]) {

        int j = 0;
        while (j < arr.length) {

            for (int i = 0; i < arr.length; i++) {
                if (i + 1 == arr.length) {
                    break;
                }
                if (arr[i] > arr[i + 1]) {
                    int temp = arr[i + 1];
                    arr[i + 1] = arr[i];
                    arr[i] = temp;
                }
            }
            j++;
        }
    }
}
